package features.advance.jdk;


import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.logging.Logger;

/**
 * @author LIN
 * @date 2021-06-16
 */
public class Demo {
    public static void main(String[] args) {
        DemoService demoService = new DemoService();
        Class<? extends Identifier> modelClass = demoService.getModelClass();
        System.out.println(modelClass);

        ArrayList<Object> list = new ArrayList<>();
        boolean b = Collections.addAll(list, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
        System.out.println(list);

    }

}
interface Identifier<T extends Serializable> {
    String DEFAULT_FILE_NAME = "id";

    T getId();

    void setId(T t);
}
class BasePO implements Identifier<String>{

    @Override
    public String getId() {
        return null;
    }

    @Override
    public void setId(String s) {

    }
}
class DemoPO extends BasePO {}
abstract class GenericUcfService<T extends Identifier<ID>, ID extends Serializable> {
    private Logger log = Logger.getLogger(this.getClass().getName());

    public Class<? extends Identifier> getModelClass() {
        Type superclassType = this.getClass().getGenericSuperclass();
        if (!ParameterizedType.class.isAssignableFrom(superclassType.getClass())) {
            log.info("泛型解析失败，可能影响特性扩展服务");
            return BasePO.class;
        } else {
            Type[] t = ((ParameterizedType)superclassType).getActualTypeArguments();
            return t != null && t.length > 0 ? (Class)t[0] : BasePO.class;
        }
    }
}
class DemoService extends GenericUcfService<DemoPO,String>{}